package com.test.webtest.config;


import com.test.webtest.intercetor.LoginIntercetor;
import com.test.webtest.intercetor.RefreshTokenIntercetor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //登录的拦截器
        registry.addInterceptor(new LoginIntercetor()).excludePathPatterns(
                "/user/code",
                "/user/login",
                //"/sort",
                //"/price",
                "/parse",
                "/sites"
                //"/sites/{id}",
                //"/certificate/generate",
                //"/cleanup/trigger"
        ).order(1);

        //刷新token的拦截器
        registry.addInterceptor(new RefreshTokenIntercetor(stringRedisTemplate)).addPathPatterns("/**").order(0);
    }
}
